package cn.echo.ecc.mq.consumer;

import cn.echo.ecc.domain.MediaFile;
import cn.echo.ecc.result.JSONResult;
import cn.echo.ecc.service.IMediaFileService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup = "course-video-push",
        topic = "topic-coursevideo",
        selectorExpression = "tag-push",
        messageModel = MessageModel.CLUSTERING)
public class CourseVideoPushConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private IMediaFileService mediaFileService;

    @Override
    public void onMessage(MessageExt messageExt) {
        String str = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        MediaFile mediaFile = JSONObject.parseObject(str, MediaFile.class);
        mediaFileService.handleFile2m3u8(mediaFile);
    }
}
